using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using System.Collections.Generic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.AutoNavigation, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_AutoNavigation : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.AutoNavigation;

        public override string name => LevelEditorConst.AutoNavigation;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("是否等待英雄")] public bool needWaitHero;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.AutoNavigation, "路径")]
        public List<Vector3> pos;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_AutoNavigation()
            {
                needWaitHero = this.needWaitHero,
                pos = new List<Int3>()
            };
            tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            for (int i = 0; i < this.pos.Count; i++)
            {
                var rPos = this.pos[i];
                rConfig.pos.Add(new Int3(rPos * 100));
            }
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_AutoNavigation rNode)
            {
                this.needWaitHero = rNode.needWaitHero;
                this.pos = new List<Vector3>(rNode.pos);
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_AutoNavigation rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}